/**
* @file log.h
* @brief 在log4cpp的基础上继续开发,实现服务器常用的回卷文件格式的日志文件，支持日志分级
*/
#ifndef TIANYU_COMMON_LOG_H_
#define TIANYU_COMMON_LOG_H_


#include <stdarg.h>
#include <string.h>
#include "common_define.h"
#include "log4cpp/Priority.hh"

namespace common
{

	enum LogLevel
	{
		LEVEL_FATAL = 0,
		LEVEL_ERROR = 300,
		LEVEL_WARN = 400,
		LEVEL_NOTICE = 500,
		LEVEL_INFO = 600,
		LEVEL_DEBUG = 700,
		LEVEL_NOTSET = 800,
	};


	int32_t InitLog(const char*	log_name,
		const char*	log_dir,
		LogLevel	log_level = LEVEL_NOTSET,
		uint32_t	max_file_size = 100 * 1024 * 1024,
		uint32_t	max_backup_index = 60,
		bool		append = true);


	int ShutdownAllLog();

	int ShutdownLog(const char *pLogName);


	int32_t Log(const char* log_name, int32_t priority_level, const char* format, ...);

}//common

#define INIT_ROLLINGFILE_LOG	::common::InitLog			// 初始化一种日志类型（基于回卷文件)
#define LOG_SHUTDOWN_ALL	::common::ShutdownAllLog()		// 关闭所有类型日志
#define LOG_SHUTDOWN		::common::ShutdownLog			// 根据日志名关闭日志

#ifdef _DEBUG_
#define LOG_DEBUG( logname, fmt, ... )	 common::Log( logname, 700,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#else
#define LOG_DEBUG( logname, fmt, ... )
#endif
#define LOG_NOTICE( logname, fmt, ... )	 common::Log( logname, 500,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#define LOG_INFO( logname, fmt, ... )	 common::Log( logname, 600,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#define LOG_WARN( logname, fmt, ... )	 common::Log( logname, 400,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#define LOG_ERROR( logname, fmt, ... )	 common::Log( logname, 300,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#define LOG_FATAL( logname, fmt, ... )	 common::Log( logname, 0  ,  "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ )
#define LOG_INFO_C( logname, fmt, ... )	 LOG_INFO( logname, fmt, ##__VA_ARGS__ )

#define LOG_DEBUG_T( fmt, ... ) LOG_DEBUG(  m_stLogCfg.szThreadKey, fmt, ##__VA_ARGS__ )
#define LOG_INFO_T( fmt, ... ) LOG_INFO(  m_stLogCfg.szThreadKey, fmt, ##__VA_ARGS__ )
#define LOG_ERROR_T( fmt, ... ) LOG_ERROR(  m_stLogCfg.szThreadKey, fmt, ##__VA_ARGS__ )

#define WARN_IF( condition, fmt, ... ) if( condition ) {  ::common::Log( "default", log4cpp::Priority::WARN, "[%s:%d][%s]" fmt, __TY_FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__ ); }

#endif

